#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
vector<int> tree[N];
int d[N];

int n;
int ans = -0x3f3f3f3f;
// 深度搜索
void dfs(int u, int father, int deep) {
  int winner = 0; // 删除u节点后的，所有子树中最大的子树规模
  d[u] = 0;       // 以u为根的树的规模
  for (auto son : tree[u]) {
    dfs(son, u, deep + 1);
    ans = max(ans, d[u] + d[son] + 1);
    d[u] = max(d[u], d[son] + 1);
  }
}

int main() {

  cin >> n;
  for (int i = 2; i <= n; i++) {
    int fa;
    cin >> fa;
    tree[fa].push_back(i);
  }
  dfs(1, 0, 0);
  cout << ans;
  return 0;
}